<template>
	<view scroll-with-animation scroll-y 
		style="height:100%;position: relative;background-color: #F8FBFB;padding-bottom: 40rpx;" v-if="medicalrecord">
		<view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;position: relative;">
			<view style="color: #00baad;font-weight: bolder;">基础资料</view>
			<view style="width: 10rpx;height: 50rpx;background-color: #00baad;position: absolute;top: 10rpx;left: 0rpx;"></view>
			<view class="card-row">
				<view>
					<text>{{medicalrecord.name}}</text>
					<text>{{medicalrecord.age}}</text>
					<text>{{medicalrecord.sex}}</text>
				</view>
			</view>
		</view>
		<template v-if="isXF==0">
			<view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;margin-top: 20rpx;position: relative;">
				<view style="color: #00baad;font-weight: bolder;">就诊记录</view>
				<view style="width: 10rpx;height: 50rpx;background-color: #00baad;position: absolute;top: 10rpx;left: 0rpx;"></view>
			</view>
			<view class="card" style="margin-top: 0rpx;">
				<view class="card-head">
					经办时间：
				</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.updatedate?medicalrecord.updatedate:'无'}}</view>
			</view>
			<view class="card">
				<view class="card-head">
					流水号：
				</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.medcalRecordId?medicalrecord.medcalRecordId:'无'}}</view>
			</view>
			<view class="card">
				<view class="card-head">主诉：</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.cheifcomplaint?medicalrecord.cheifcomplaint:'无'}}</view>
			</view>
			<view class="card">
				<view class="card-head">现病史：</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.historypresentillness?medicalrecord.historypresentillness:'无'}}</view>
			</view>
			<view class="card">
				<view class="card-head">诊断概述:</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.outpatientdiagnosis?medicalrecord.outpatientdiagnosis:'无'}}</view>
			</view>
			<view class="card">
				<view class="card-head">诊断经过:</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.diagnosistreatment?medicalrecord.diagnosistreatment:'无'}}</view>
			</view>
			<view class="card">
				<view class="card-head">主治医生:</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.attendingphysician?medicalrecord.attendingphysician:'无'}}</view>
			</view>
			<view class="card">
				<view class="card-head">诊疗意见:</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.orderinfo?medicalrecord.orderinfo:'无'}}</view>
			</view>
			
			<view class="card">
				<view class="card-head">首诊医院:</view>
				<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.hspName?medicalrecord.hspName:'无'}}</view>
			</view>
		</template>
		<template v-else>
			<view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;position: relative;">
				<view style="color: #00baad;font-weight: bolder;">处方详情</view>
				<view style="width: 10rpx;height: 50rpx;background-color: #00baad;position: absolute;top: 10rpx;left: 0rpx;"></view>
			</view>
			<view style="padding-left: 40rpx;padding-bottom: 40rpx;display: flex;align-items: center;">
				<view style="width: 33%;">
					<text style="margin-right: 10rpx;">患者姓名</text>
					<text>{{recipeDetail.treatName}}</text>
				</view>
				<view style="width: 33%;">
					<text style="margin-right: 10rpx;">性别</text>
					<text>{{recipeDetail.treatSex}}</text>
				</view>
				<view style="width: 33%;">
					<text style="margin-right: 10rpx;">年龄</text>
					<text>{{recipeDetail.treatAge}}</text>
				</view>
			</view>
			<view style="padding-left: 40rpx;padding-bottom: 40rpx;display: flex;align-items: center;">
				<view style="width: 45%;">
					<text style="margin-right: 10rpx;">科室</text>
					<text>{{recipeDetail.deptName}}</text>
				</view>
				<view style="width: 45%;" v-if="recipeDetail">
					<text style="margin-right: 10rpx;">日期</text>
					<text>{{formatDate(recipeDetail.sendDate)}}</text>
				</view>
			</view>
			<view style="padding-left: 40rpx;padding-bottom: 40rpx;display: flex;align-items: center;">
				<view style="width: 100%;">
					<text style="margin-right: 10rpx;">主诉</text>
					<text>{{recipeDetail.problem}}</text>
				</view>
			</view>
			<view style="padding-left: 40rpx;padding-bottom: 40rpx;display: flex;align-items: center;">
				<view style="width: 100%;">
					<text style="margin-right: 10rpx;">诊断</text>
					<text v-for=" diseaItem in recipeDetail.diseaInfo" :key="diseaItem.diseDiseaseId">{{diseaItem.name+' '}}</text>
				</view>
			</view>
			
			<view style="padding-left: 40rpx;padding-bottom: 40rpx;display: flex;align-items: center;" v-if="recipeDetail.chinRecipeType==2">
				<view style="width: 100%;">
					<text style="margin-right: 10rpx;">中医诊断：</text>
				<text>{{recipeDetail.disNames?recipeDetail.disNames:'--'}}</text></view>
			</view>
			<view style="padding-left: 40rpx;padding-bottom: 40rpx;display: flex;align-items: center;" v-if="recipeDetail.chinRecipeType==2">
				<view style="width: 100%;">
					<text style="margin-right: 10rpx;">中医辩证：</text>
				<text>{{recipeDetail.symNames?recipeDetail.symNames:'--'}}</text></view>
			</view>
			<view style="padding-left: 40rpx;padding-bottom: 40rpx;display: flex;align-items: center;" v-if="recipeDetail.chinRecipeType==2">
				<view style="width: 100%;">
					<text style="margin-right: 10rpx;">中医辩证治法：</text>
				<text>{{recipeDetail.theNames?recipeDetail.theNames:'--'}}</text></view>
			</view>
			
			<view class="pl20 pr20 mt20 ft17 c74a6fd bold">Rp:</view>
			<view class="medicine">
				<view v-for="(item,index) in recipeDetail.userRecipeDrug" :key="item.id">
					<view class="pl20 pr20 pb10 pt10 mt20">
						<view class="pl20 pr20">
							<view class="flex flex-ac flex-pj">
								<text>{{item.drugName}}</text>
								<text class="ft12 c666">*{{item.num}}</text>
							</view>
							<view class="flex flex-ac ft12 c666 mt20">
								<!-- <text class="it1">{{item.drugFrequency}}</text>
								<text class="it1">{{item.drugRoute}}</text>
								<text class="it1">{{item.drugSpecificationName}}</text>
								<text v-if="chinRecipeType!=2">用法：{{item.drugDosage}}</text>
								<text v-if="chinRecipeType==2">用法：
									<text v-if="item.specialUse">{{item.specialUse}}{{item.speciaUseTime}}</text>
									<text v-else>暂无特殊用法</text>
								</text> -->
								<template v-if="recipeDetail.chinRecipeType==2">
									<text class="it1">{{item.drugFrequency}}</text>
									<text class="it1">{{item.drugRoute}}</text>
									<text class="it1">{{item.drugSpecificationName}}</text>
									<text>用法：
										<text v-if="item.specialUse">{{item.specialUse}}{{item.speciaUseTime}}</text>
										<text v-else>暂无特殊用法</text>
									</text>
								</template>
								<template v-else>
									<text class="it1">{{item.drugRoute}}</text>
									<text class="it1">{{item.drugFrequency}}</text>
									<text class="it1">每次{{item.drugDosage}}</text>
									<text>{{item.drugSpecificationName}}</text>
								</template>
							</view>
						</view>
					</view>
				</view>
			</view>
		</template>
		<view class="card">
			<view class="card-head">症状描述:</view>
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.problem?medicalrecord.problem:'无'}}</view>
		</view>
		<!-- <view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;">
			<view style="color: #4CD964;">症状描述</view>
		</view>
		<view class="card">
			<view style="width: calc(100% - 40rpx);margin-top: 20rpx;">{{medicalrecord.problem}}</view>
		</view> -->
		<view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;margin-top: 20rpx;position: relative;">
			<view style="color: #00baad;font-weight: bolder;">{{ orderId.indexOf('_chinOrd')>-1?'舌苔、舌底照片':'患处图片'}} </view>
			<view style="width: 10rpx;height: 50rpx;background-color: #00baad;position: absolute;top: 10rpx;left: 0rpx;"></view>
		</view>
		<view style="padding-left: 40rpx;padding-right: 40rpx;display: flex;align-items: center;flex-wrap: wrap;background-color: #FFFFFF;padding-bottom: 30rpx;">
			<image v-for="(imgItem,idx) in img_1" :key="idx" :src="imgItem" style="width: 180rpx;height: 180rpx;margin-right: 20rpx;" mode="scaleToFill"></image>
		</view>
		
		<view style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;margin-top: 20rpx;position: relative;">
			<view style="color: #00baad;font-weight: bolder;">历史诊疗信息</view>
			<view style="width: 10rpx;height: 50rpx;background-color: #00baad;position: absolute;top: 10rpx;left: 0rpx;"></view>
		</view>
		<view style="padding-left: 40rpx;padding-right: 40rpx;display: flex;align-items: center;flex-wrap: wrap;background-color: #FFFFFF;padding-bottom: 30rpx;">
			<image v-for="(imgItem,idx) in img_2" :key="idx" :src="imgItem" style="width: 180rpx;height: 180rpx;margin-right: 20rpx;" mode="scaleToFill"></image>
		</view>
		
		<view v-if="problemList" style="background-color: #FFFFFF;padding-left: 40rpx;padding-bottom: 20rpx;font-size: 30rpx;padding-top: 20rpx;margin-top: 20rpx;position: relative;">
			<view style="color: #00baad;font-weight: bolder;">问诊单</view>
			<view style="width: 10rpx;height: 50rpx;background-color: #00baad;position: absolute;top: 10rpx;left: 0rpx;"></view>
			<view v-for="(proItem,proIdx) in problemList" :key="proIdx">
				<!-- <view>{{proItem.problem}}</view> -->
				<view>
					<text v-for=" (answerItem,answerIdx) in proItem.answerList" :key="answerIdx">{{answerItem}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				img_1:[],
				img_2:[],
				orderId: undefined,
				usrPersonId: undefined,
				medicalrecord:undefined,
				recipeDetail:undefined,
				problemList:undefined,
				isXF:undefined
			};
		},
		onLoad(option) {
			this.orderId = option.orderId
			this.usrPersonId = option.usrPersonId
			this.isXF = option.isXF
			console.log(option.isXF)
			this.recipeId = option.recipeId
			this.getUserPersonalMedical()
			if(this.isXF == 1 && this.recipeId){
				this.getDrugListByRecipeId()
			}
			if(this.orderId.indexOf('_chinOrd')>-1){
				this.getChinMedConInfo()
			}
		},
		methods: {
			jsage(age){
				let ageNUm = age/12
				if(ageNUm.toString().indexOf('.')>-1){
					let ageStr = ageNUm.toString()
					return ageStr.substring(0,ageStr.indexOf('.'))
				}else{
					return ageNUm.toString()
				}
			},
			getUserPersonalMedical(){
				let data={
					orderId : this.orderId,
					usrPersonId:this.usrPersonId,
					isXF:this.isXF
				}
				this.func.$request('wx/getUserPersonalMedical.tz',data,'GET').then(res=>{
					if(res.data.success){
						console.log('WxQueryPersonalId',res.data.result)
						this.medicalrecord = res.data.result;
						console.log(this.medicalrecord,111)
						this.img_1 = this.medicalrecord.list.filter(item=>item.indexOf('_zhenliao')<0)
						this.img_2 = this.medicalrecord.list.filter(item=>item.indexOf('_zhenliao')>-1)
						// this.problem = res.data.result.problem
						// that.collectForDoctor = res.data.result;
					}
				})
			},
			getDrugListByRecipeId(){
				this.func.$request('recipe/detail.tz',{recipeId: this.recipeId},'GET').then(res=>{
					if (res.data.success = true) {
						this.recipeDetail = res.data.result
					}
				})
			},
			getChinMedConInfo(){
				this.fucn.$request('chinMed/getChinMedConInfo.tz',{orderId: this.orderId},'GET').then(res=>{
					if (res.data.success = true) {
						this.problemList = res.data.result.problemList
					}
				})
			},
			formatDate(value) {
			  var date = new Date(value);
			  var y = date.getFullYear(),
			    m = date.getMonth() + 1,
			    d = date.getDate(),
			    h = date.getHours(),
			    i = date.getMinutes(),
			    s = date.getSeconds();
			  if (m < 10) { m = '0' + m; }
			  if (d < 10) { d = '0' + d; }
			  if (h < 10) { h = '0' + h; }
			  if (i < 10) { i = '0' + i; }
			  if (s < 10) { s = '0' + s; }
			  var t = y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
			  return t;
			}
		}
	};
</script>

<style lang="less">
	.card-row{
		width: calc(100% - 40rpx);
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 20rpx;
	}
	.card-head{
		font-size: 30rpx;
		font-weight: bolder;
		width: calc(100% - 40rpx);
		border-bottom: 2rpx solid #E1E1E1;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}
	.card{
		background-color: #FFFFFF;
		padding-left: 40rpx;
		margin-top: 20rpx;
		padding-bottom: 20rpx;
	}
</style>
